package com.ming.stringstudy.feedbacksystem.utils;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ming.stringstudy.feedbacksystem.entity.RolePermission;
import com.ming.stringstudy.feedbacksystem.mapper.RolePermissionMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Slf4j
@Component
public class PermissionUtils {
    @Autowired
    private RolePermissionMapper rolePermissionMapper;
    /**
     * 查询该角色是否有该权限
     * @param roleId
     * @param permissionId
     * @return
     */
    public boolean equalPermission(Integer roleId, Integer permissionId) {
        QueryWrapper<RolePermission> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("role_id", roleId);
        queryWrapper.eq("permission_id", permissionId);
        List<RolePermission> rolePermissions = rolePermissionMapper.selectList(queryWrapper);
        return !rolePermissions.isEmpty();
    }
}
